<template>
  <div class="main">
    <!--<div class="header_title">验证注册手机</div>-->
    <div class="register-form">
      <div class="phone">
        <van-field
          v-model="data.IDCard"
          label="身份证"
          required
          placeholder="请输入身份证"
        />
      </div>
      <div class="btns m-10">
        <van-button @click="login()"> 验证 </van-button>
        <van-button type="green" class="ml-10" @click="register()">
          注册
        </van-button>
      </div>
    </div>
  </div>
</template>

<script>
import { idCardLoginVerify } from "@/api/public";
export default {
  components: {},
  data() {
    return {
      data: {
        IDCard: "",
        OpenID: this.$store.state.openId,
        CompanyCode: this.$route.query.CompanyCode,
      },
    };
  },
  methods: {
    login() {
      if (!this.data.IDCard) {
        this.$toast("请输入身份证号");
        return;
      }
      idCardLoginVerify(this.data)
        .then((res) => {
          this.$toast("验证成功,即将跳转");
          this.$store.commit("setBaseUrl", process.env.VUE_APP_BASE_API);
          // 修改登陆状态
          this.$store.commit("updateLogin", true);
          // 把token存入store
          this.$store.commit("updateToken", res.data.UserName);
          // 把用户名存入store
          this.$store.commit("updateUsername", res.data.ChnName);
          // 保存地址 updateArea
          this.$store.commit("updateArea", res.data.ApplyArea);
          // 保存地址 updateArea
          this.$store.commit("updateCompanySysType", res.data.CompanySysType);
          // 公司code
          this.$store.commit("updateCompanyCode", res.data.CompanyCode);
          this.$store
            .dispatch("getRoles", res.data.UserKind)
            .then((data) => {
              console.log(data);
            })
            .catch((_) => {
              failure("获取失败");
            });
          setTimeout(() => {
            this.$router.push(
              "/index?num=" + Math.ceil(Math.random() * 100000)
            );
          }, 1500);
        })
        .catch((err) => {
          this.$toast(err.message);
        });
    },
    register() {
      this.$router.push({
        path: "/registerPhone",
        query: {
          CompanyCode: this.data.CompanyCode,
          dType: "sgfCompany"
        },
      });
      // this.$router.push({
      //   path: "/registerIDCard",
      //   query: {
      //     CompanyCode: this.data.CompanyCode,
      //   },
      // });
    },
  },
};
</script>

<style lang="less" scoped>
/*.register-form {*/
/*    margin-top: 10px;*/
/*}*/
.phone {
  position: relative;

  .code {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 12px;
  }
}
</style>



